<template>
  <div>
    <!-- 补贴信息上报 -->
    <TopFilter
      :list="topFilterList"
      :cols="3"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
      :labelWidth="110"
      @resetChange="resetChange"
    ></TopFilter>

    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      columnsRef="zjsubsidyUpload"
      :onRowSelectChange="selectChangeHandle"
      :isSelectColumn="false"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls" slot-scope="props"></template>
    </FilterTable>
    <Drawer
      :visible.sync="detailvisible"
      :title="'详情'"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
      width="85%"
    >
      <childrenModel :rowData="formData" @close="detailcloseHandler" />
    </Drawer>
    <Drawer
      :visible.sync="emitvisible"
      :title="'编辑'"
      destroyOnClose
      :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }"
      width="85%"
    >
      <emitModel :rowData="formData" @close="emitcloseHandler" />
    </Drawer>
  </div>
</template>
<script>
import { getList, getDetail, updatePlateApply, exportList } from '@/api/dealerSale/subsidy/subsidyUpload/index.js';
import childrenModel from './childrenModel';
import emitModel from './emitModel';
import { dictionary } from '@/utils/dictMixin';
import { exportExcelFile } from '@/utils';
export default {
  name: 'TemplateDistribution',
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchParams: {
        xhrAbort: true,
        isFilter: 1
      },
      fetchApi: getList,
      formData: {},
      detailvisible: false,
      emitvisible: false,
      selectedList: []
    };
  },
  mixins: [dictionary],
  components: {
    childrenModel,
    emitModel
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {},
  methods: {
    createdFrom() {
      return [
        {
          type: 'TEXT_AREA',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请输入',
          maxlength: '',
          maxRows: 2
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'customerName',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'plateNumber',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '发票号码',
          fieldName: 'invoiceNo',
          placeholder: '请输入'
        },
        {
          type: 'SELECT',
          label: '省份',
          fieldName: 'provinceId',
          placeholder: '请选择',
          itemList: this.createRegionsList()
        },

        {
          type: 'SELECT',
          label: '审批状态',
          fieldName: 'applyStatus',
          placeholder: '请选择',
          itemList: [
            { text: '待提交（保存）', value: 60191001 },
            { text: '审核驳回', value: 60191004 }
          ]
        },
        {
          type: 'RANGE_DATE',
          label: '发票日期',
          fieldName: 'startInvoiceDate|endInvoiceDate',
          placeholder: '请选择',
          initialValue: [],
          dateType: 'exactdaterange'
        },
        {
          type: 'RANGE_DATE',
          label: '行驶证注册日期',
          fieldName: 'startRegisterDate|endRegisterDate',
          placeholder: '请选择',
          initialValue: [],
          dateType: 'exactdaterange'
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row, 1)}>
                  详情
                </multiuse-button>
                <el-divider direction="vertical" />
                <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row, 2)} disabled={!(props.row.applyStatus == 60191001 || props.row.applyStatus == 60191004)}>
                  编辑
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '审批状态',
          dataIndex: 'applyStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [
            { text: '待提交（保存）', value: 60191001 },
            { text: '审核驳回', value: 60191004 }
          ],
          render: p => {
            return <span>{this.createDictText(p.row.applyStatus, '6019')}</span>;
          }
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户类型',
          dataIndex: 'customerType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1523'),
          render: p => {
            return <span>{this.createDictText(p.row.customerType, '1523')}</span>;
          }
        },
        {
          title: '手机号',
          dataIndex: 'linkPhone',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN码',
          dataIndex: 'vin',
          align: 'center',
          width: 180,
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '车系名称',
          dataIndex: 'seriesName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型名称',
          dataIndex: 'modelName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配置名称',
          dataIndex: 'packageName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '选装名称',
          dataIndex: 'optionName',
          align: 'center',
          width: 250,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '内饰',
          dataIndex: 'trimName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '颜色',
          dataIndex: 'colorName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品代码',
          dataIndex: 'productCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品名称',
          dataIndex: 'productName',
          align: 'center',
          width: 400,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '公告号',
          dataIndex: 'announceNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '开票日期',
          dataIndex: 'invoiceDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '发票号码',
          dataIndex: 'invoiceNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车辆性质',
          dataIndex: 'vehicleType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('4103'),
          render: p => {
            return <span>{this.createDictText(p.row.vehicleType, '4103')}</span>;
          }
        },
        {
          title: '证件类型',
          dataIndex: 'cardType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1508'),
          render: p => {
            return <span>{this.createDictText(p.row.cardType, '1508')}</span>;
          }
        },

        {
          title: '证件号码',
          dataIndex: 'cardNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '联系人',
          dataIndex: 'linkMan',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '省份',
          dataIndex: 'provinceName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '城市',
          dataIndex: 'cityName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '区县',
          dataIndex: 'districtName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '详细地址',
          dataIndex: 'linkAddress',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '邮编',
          dataIndex: 'zipCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '车牌号',
          dataIndex: 'plateNumber',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '行驶证注册日期',
          dataIndex: 'drivingRegisteDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '行驶证号',
          dataIndex: 'drivingNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '电机号',
          dataIndex: 'motorNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '电池号',
          dataIndex: 'batteryNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '销售顾问',
          dataIndex: 'salesManName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '申请日期',
          dataIndex: 'applyDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '审批日期',
          dataIndex: 'checkDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '审批意见',
          dataIndex: 'checkDesc',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    selectChangeHandle(row) {},
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params, { xhrAbort: false });
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    editHandle(data, type) {
      this.formData = data;
      if (type == 1) {
        this.detailvisible = true;
      } else {
        this.emitvisible = true;
      }
    },
    detailcloseHandler() {
      this.detailvisible = false;
    },
    emitcloseHandler(val) {
      this.emitvisible = false;
      if (val) {
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
    },
    resetChange() {
      this.topFilterList.map(x => {
        if (x.fieldName == 'plateCity') {
          x.itemList = [];
          x.initialValue = '';
        }
      });
      this.fetchParams = Object.assign({}, this.fetchParams);
    }
  }
};
</script>
